package com.probiz.estoremf.content.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.catalog.service.ContentCategoryManager;
import com.probiz.estore.common.model.content.Content;
import com.probiz.estore.common.model.product.Product;
import com.probiz.estore.common.model.product.ProductAttGroup;
import com.probiz.estore.content.service.ContentManager;
import com.probiz.estore.content.service.ContentNtManager;
import com.probiz.estore.core.controller.GenericStoreFrontController;

public class ContentFrontController extends	GenericStoreFrontController<Content> {
	private ContentManager	contentManager;
	private ContentNtManager	contentNtManager;
	private ContentCategoryManager	contentCategoryManager;
	

	public void setContentManager(ContentManager contentManager) {
		this.contentManager = contentManager;
	}

	public void setContentNtManager(ContentNtManager contentNtManager) {
		this.contentNtManager = contentNtManager;
	}


	public void setContentCategoryManager(ContentCategoryManager contentCategoryManager) {
		this.contentCategoryManager = contentCategoryManager;
	}

	protected void initController() throws Exception {
		mgr = contentManager;
	}

	public ModelAndView defaultAction(HttpServletRequest request,HttpServletResponse response) {
		Integer contentId = contentManager.getContentIdByUri(request.getRequestURI());
		Content content = contentManager.getById(contentId);
		// 没有找到相应文章或文章状态的不能访问,直接进入找不到或已删除页面
		if (content == null	|| content.getStatus().shortValue() != Content.STATUS_PUBLISHED.shortValue()) {
			ModelAndView mv = new ModelAndView("content/contentUnAvailable");
			mv.addObject("category",contentCategoryManager.getById(Integer.valueOf(1)));
			return mv;
		}
		ModelAndView mv = new ModelAndView("content/defaultContentDetail");
		mv.addObject("content",content);
		mv.addObject("category",content.getCategory());
		
		//start:记录点击率
		contentNtManager.recordViewCount(contentId, request.getSession());
		//end:  记录点击率
		return mv;
	}



	
}
